home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 552 / dcs_s1 / dcs_s1.s < prev   
Encoding:
Text File  |  1991-10-11  |  4.8 KB  |  196 lines

  1. * TAB=10 (why? that's how my DevPac came way back when...)
  2. *
  3. * DCS.S - Assembly Lesson # 1
  4. *   by Keith Gerdes
  5. *    & Michael B. Vederman
  6. *
  7. * Developed and tested using HiSoft's DevPac ST/TT
  8. *
  9.  
  10. * Equates for picture file type
  11. *  Change "type_pic" variable in DATA segment to desired picture type
  12. NEO    = 0
  13. PIx    = 1
  14. * NOTE: PIx refers to PI1, PI2 or PI3 file
  15.  
  16.     TEXT            ; TEXT segment
  17. START:
  18. * Get new screen address (STs require a 256 ($100) byte boundary)
  19.     move.l    #buffer,d0    ; 32000+256 byte buffer
  20.     clr.b    d0        ; $100 byte boundary round off
  21.     add.l    #$100,d0        ; now round up
  22.     move.l    d0,new_scrn    ; new screen buffer
  23.  
  24. * Get current resolution
  25.     move.w    #4,-(a7)
  26.     trap    #14        ; getRez
  27.     addq.l    #2,a7
  28.     move.w    d0,rez        ; resolution (0,1,2)
  29.     move.w    d0,the_rez    ; resolution variable
  30.  
  31. * Get current screen address
  32.     move.w    #2,-(a7)
  33.     trap    #14        ; physBase
  34.     addq.l    #2,a7
  35.     move.l    d0,old_scrn    ; present screen address
  36.  
  37.     dc.w    $a00a        ; hide mouse cursor
  38.  
  39. * Open picture file
  40.     lea    name_neo,a0    ; NEO
  41.     cmp.b    #NEO,type_pic    ; NEO?
  42.     beq.s    f_open        ; yep
  43.     lea    name_pix,a0    ; PIx
  44. f_open:    move.l    a0,-(a7)        ; filename
  45.     move.w    #$3d,-(a7)
  46.     trap    #1        ; Fopen
  47.     addq.l    #6,a7
  48.     tst.l    d0
  49.     bmi    exit1        ; error
  50.     move.w    d0,handle
  51.  
  52. * Read resolution & palette
  53.     lea    the_pal,a0    ; buffer
  54.     moveq    #34,d0        ; count (1.w+16.w)
  55.     cmp.b    #PIx,type_pic    ; PIx?
  56.     beq.s    get_f_pal        ; yep
  57.     moveq    #36,d0        ; count (2.w+16.w)
  58. get_f_pal:bsr    f_read        ; read
  59.     ble    exit1        ; error
  60.  
  61. * Get current color palette
  62. * Note: registers D3-D7 & A3-A7 are saved by TRAP #13 & #14
  63.     lea    save_pal+32,a6
  64.     moveq    #15,d7
  65. get_pal:    move.w    #-1,-(a7)        ; color value (-1 gets color)
  66.     move.w    d7,-(a7)        ; color #
  67.     move.w    #7,-(a7)
  68.     trap    #14        ; get/set color
  69.     addq.l    #6,a7
  70.     move.w    d0,-(a6)        ; save it
  71.     dbf    d7,get_pal
  72.  
  73. * Set palette (all black)
  74.     lea    clr_pal,a0    ; palette address (all zeroes)
  75.     bsr    set_pal        ; set palette
  76. * Set screen to new resolution & address
  77.     move.w    the_pal,d0    ; resolution
  78.     and.w    #3,d0        ; see text
  79.     move.l    new_scrn,a0    ; change screen location
  80.     bsr    setscreen        ; set screen
  81.  
  82.     cmp.b    #PIx,type_pic    ; PIx?
  83.     beq.s    get_data        ; yep
  84.  
  85. * Dummy read of NEO header...could have done an Fseek
  86.     move.l    new_scrn,a0    ; buffer
  87.     moveq    #92,d0        ; count (128-36)
  88.     bsr    f_read        ; read
  89.     ble.s    exit1        ; error
  90.  
  91. * Read screen data
  92. get_data:    move.l    new_scrn,a0    ; buffer
  93.     move.l    #32000,d0        ; count
  94.     bsr    f_read        ; read
  95.     ble.s    exit1        ; error
  96.  
  97. * Set new palette
  98. *  Palette read at +2 for PIx & +4 for NEO
  99.     lea    the_pal+2,a0    ; palette address
  100.     cmp.b    #PIx,type_pic    ; PIx?
  101.     beq.s    scrn_pal        ; yep
  102.     lea    the_pal+4,a0    ; palette address
  103. scrn_pal:    bsr    set_pal        ; set palette
  104.  
  105. * Wait for keypress
  106.     move.w    #7,-(a7)
  107.     trap    #1        ; Crawcin
  108.     addq.l    #2,a7
  109.  
  110.  
  111. * Set palette (all black)
  112.     lea    clr_pal,a0    ; palette address (all zeroes)
  113.     bsr.s    set_pal        ; set palette
  114.  
  115. * Restore screen resolution & address
  116.     move.w    rez,d0        ; original resolution
  117.     move.l    old_scrn,a0    ; original screen address
  118.     bsr.s    setscreen        ; set screen
  119. * Restore palette
  120.     lea    save_pal,a0    ; original palette
  121.     bsr.s    set_pal        ; set palette
  122.  
  123. exit1:    dc.w    $a009        ; show mouse cursor
  124.  
  125. * Close file handle
  126.     tst.w    handle        ; file opened?
  127.     ble.s    exit2        ; nope
  128.     move.w    handle,-(a7)    ; handle
  129.     move.w    #$3e,-(a7)
  130.     trap    #1        ; Fclose
  131.     addq.l    #4,a7
  132.  
  133. * Terminate
  134. exit2:    clr.w    -(a7)
  135.     trap    #1        ; Pterm
  136.     illegal            ; won't get here?
  137.  
  138. * D0 = resolution
  139. * A0 = new screen address
  140. setscreen:cmp.w    #2,d0        ; hi rez switch?
  141.     beq.s    no_change        ; yep
  142.     cmp.w    #2,rez        ; in hi rez?
  143.     beq.s    no_change        ; yep
  144.     lea    the_rez,a1
  145.     move.w    (a1),d1        ; old rez
  146.     move.w    d0,(a1)        ; new rez
  147.     cmp.w    d1,d0        ; same?
  148.     bne.s    new_rez        ; nope - do rez change
  149. no_change:moveq    #-1,d0        ; -1 no change
  150. new_rez:    move.w    d0,-(a7)        ; rez (0,1,2)
  151.     move.l    a0,-(a7)        ; physical location
  152.     move.l    a0,-(a7)        ; logical location
  153.     move.w    #5,-(a7)
  154.     trap    #14        ; setScreen
  155.     lea    12(a7),a7
  156.     rts
  157.  
  158. * A0 = palette address
  159. set_pal:    move.l    a0,-(a7)        ; push palette for below
  160.  
  161.     move.w    #37,-(a7)
  162.     trap    #14        ; vsync
  163.     addq.l    #2,a7
  164.  
  165.     move.w    #6,-(a7)
  166.     trap    #14        ; set palette
  167.     addq.l    #6,a7
  168.     rts
  169.  
  170. * A0 = buffer address
  171. * D0 = amount to read
  172. f_read:    move.l    a0,-(a7)        ; buffer
  173.     move.l    d0,-(a7)        ; count
  174.     move.w    handle,-(a7)    ; handle
  175.     move.w    #$3f,-(a7)
  176.     trap    #1        ; Fread
  177.     lea    12(a7),a7
  178.     tst.l    d0        ; test error condition for return
  179.     rts
  180.  
  181.     DATA            ; DATA segment
  182. name_neo:    dc.b    '*.neo',0        ; NEO filename
  183. name_pix:    dc.b    '*.pi?',0        ; PIx filename
  184. type_pic:    dc.b    NEO        ; picture type 0-NEO !0-PIx
  185.  
  186.     BSS            ; BSS segment
  187. rez:    ds.w    1        ; original resolution value
  188. the_rez:    ds.w    1        ; resolution variable
  189. handle:    ds.w    1        ; file handle from Fopen
  190. new_scrn:    ds.l    1        ; address of allocated screen
  191. old_scrn:    ds.l    1        ; saved address of original screen
  192. save_pal:    ds.w    16        ; saved palette
  193. clr_pal:    ds.w    16        ; palette of 0s to blank screen
  194. the_pal:    ds.w    36        ; new palette read from pic file
  195. buffer:    ds.b    32000+256        ; buffer for screen
  196.